﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Bll.UserBase;
using Besture.Model;
using Besture.Model.XiangSheng;
using Besture.Common;
using Besture.Common.Helper;
using Besture.UI.Common;

namespace Besture.UI.Portal.Pay
{
    public partial class OrderDetail : UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OrderInfo_Order_Model model = (OrderInfo_Order_Model)Session["OrderInfo"];

                if (model != null)
                {
                    this.lblHotelName1.Text = model.HotelsName;
                    this.lblHotelName2.Text = model.HotelsName;
                    this.lblBeginTime.Text = model.BeginTime;
                    this.lblEndTime.Text = model.EndTime;
                    this.lblDay1.Text = model.DaySpan.ToString() + "晚";
                    this.lblDay2.Text = model.DaySpan.ToString() + "晚";
                    this.lblRoomName.Text = model.RoomName;
                    this.lblPrice.Text = model.Price;
                    this.lblBreakfast.Text = model.Breakfast;
                    this.lblRoomNum.Text = model.RoomQuantity;
                    this.lblUserName.Text = model.UserName1 + " " + model.UserName2;
                    this.lblArrive.Text = model.Arrive;
                    this.lblCustomer.Text = model.Customer;
                    this.lblPhone.Text = model.Phone;
                    this.lblEmail.Text = model.Email;
                    this.lblRemark.Text = model.RequireText + " " + model.Remark;
                    this.lblTotal.Text = this.lblScore.Text = model.TotalPrice;
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session[Constants.SESSION_WEB_USER_MODEL] != null)
            {
                OrderInfo_Order_Model model = (OrderInfo_Order_Model)Session["OrderInfo"];
                UserBaseModel ubm = ((UserBaseModel)HttpContext.Current.Session[Constants.SESSION_WEB_USER_MODEL]);
                OrderDac dac = new OrderDac();


                int result = dac.AddNoPayOrder(model, ubm.ID);
                if (result > 0 )
                { 
                    //201507291530 lyg 添加log日志 start
                    string sLogContent = string.Format("{0}已在{1}已下单成功(订单号：{2})",
                        GetUserLoginModel().LoginName,
                        DateTime.Now.ToString(),new OrderDac().GetModel(result).OrderNo);
                    new OrderLogDac().Add(sLogContent, result);
                    //201507291530 lyg 添加log日志 end

                    Response.Redirect("OrderAffirm.aspx?OrderId=" + result);
                }
                else
                {
                    FunHelper.Alert("下单失败，请重新尝试！");
                }
            }
            else
            {
                FunHelper.Alert("超时，请重新登录！", "../UserCenter/Login.aspx");
            }
        }
    }
}